package com.sc.controller.csm;

import com.sc.domain.Employee;
import com.sc.dto.EmployeeDTO;
import com.sc.result.PageResult;
import com.sc.result.Result;
import com.sc.service.csm.IEmployeeService;
import com.sc.vo.EmployeeVO;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Api(tags = "设置-员工管理")
@CrossOrigin
@RestController
@RequestMapping("/employee")
@RequiredArgsConstructor
public class EmployeeController {

    private final IEmployeeService employeeService;

    @PostMapping("/add")
    public Result add(@RequestBody Employee employee) {
        employee.setAddTime(LocalDateTime.now());
        return Result.success("添加成功", employeeService.save(employee));
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id) {
        return Result.success("删除成功", employeeService.removeById(id));
    }

    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        return Result.success("删除成功", employeeService.removeByIds(ids));
    }

    @PutMapping("/update")
    public Result update(@RequestBody Employee employee) {
        return Result.success("修改成功", employeeService.updateById(employee));
    }

    @GetMapping("/selectById")
    public Result<Employee> selectById(Integer id) {
        return Result.success(employeeService.getById(id));
    }

    @PostMapping("/pageQuery")
    public Result<PageResult<EmployeeVO>> pageQuery(@RequestBody EmployeeDTO employeeDTO) {
        return Result.success(employeeService.pageQuery(employeeDTO));
    }
}
